import config from '@/config/config.js';
import axios from "axios";


const iqcRequest={
    loadIqcs(iqc,page=1,limit=10,callBack){
        let url = config.qualityBaseUrl + "/iqc/list?page="+page + "&limit="+limit;
        if(iqc){
            if(iqc.iqcCode){
                url += "&iqcCode=" + iqc.iqcCode;
            }

            if(iqc.vendorCode){
                url += "&vendorCode="+iqc.vendorCode;
            }
            if(iqc.vendorName){
                url += "&vendorName="+iqc.vendorName;
            }
            if(iqc.vendorBatch){
                url += "&vendorBatch="+iqc.vendorBatch;
            }
            if(iqc.itemCode){
                url += "&itemCode="+iqc.itemCode;
            }
            if(iqc.itemName){
                url += "&itemName="+iqc.itemName;
            }
            if(iqc.checkResult){
                url += "&checkResult="+iqc.checkResult;
            }
            if(iqc.reciveDate){
                url += "&reciveDate="+iqc.reciveDate;
            }
            if(iqc.inspectDate){
                url += "&inspectDate="+iqc.inspectDate;
            }
            if(iqc.inspector){
                url += "&inspector="+iqc.inspector;
            }

        }

        // 发送请求
        axios.get(url)
            .then(res=>{
                // 回调函数是从外面传入的，我们要将我们请求得到的结果传回到回调函数中.
                // 由于axiso会对结果进行一个封装，所以我们这里传入回调函数的数据直接就是res.data
                // 我们在外面获取的数据就是我们后端响应的数据本身。
                callBack(res.data);
            })



    },


    addIqc(iqc,callBack){
        console.log(iqc)
        let url = config.qualityBaseUrl + "/iqc/add"
        axios.post(url,iqc)
            .then(res=>{
                callBack(res.data);
            })
    },


    selectIqcById(iqcId,callBack){
        let url = config.qualityBaseUrl + "/iqc/selectIqcById?iqcId=" + iqcId;
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },

    updateIqc(iqc,callBack){
        let url = config.qualityBaseUrl + "/iqc/update"
        axios.put(url,iqc)
            .then(res=>{
                callBack(res.data);
            })
    }











}


export default iqcRequest;